gl: Tweak the swizzle for GLES texture fragments
authorEmmanuele Bassi <ebassi@gnome.org>
Sat, 23 Apr 2016 12:52:03 +0000 (13:52 +0100)
committerEmmanuele Bassi <ebassi@gnome.org>
Mon, 25 Apr 2016 11:29:37 +0000 (12:29 +0100)
Cairo surfaces are in BGRA format, but we upload them as RGBA buffers on
GLES; this means that the R and B channels are flipped in the texture
data.

Instead of doing a costly channel flip before putting them on the GPU,
we can flip the values inside the GLSL shader we use specifically for
GLES.

gdk/resources/glsl/gles2-texture.fs.glsl

index 68e455fcf387066348269f7d98be102271eed4f3..56c6c8200268449f4171483ec443f6d36d3a9531 100644 (file)
@@ -5,5 +5,8 @@ uniform sampler2D map;
 varying highp vec2 vUv;
 
 void main() {
-  gl_FragColor = texture2D(map, vUv);
+  vec4 color = texture2D(map, vUv);
+
+  /* Flip R and B around to match the Cairo convention */
+  gl_FragColor = vec4(color.z, color.y, color.x, color.w);
 }